<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('走访地址簿列表')"/>
</head>
<style>
    .btn-police {
        background-color: #03a9f4;
        border-color: #03a9f4;
        color: #FFFFFF;
    }

    .btn-police:hover {
        color: #fff;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>地址名称：</label>
                            <input type="text" name="dzmc-like"/>
                        </li>
                        <li>
                            <label style="width: 100px;">所属警务区：</label>
                            <input type="text" name="ssjwq"/>
                        </li>
                        <li>
                            <label style="width: 100px;">所属街路巷：</label>
                            <input type="text" name="ssjlxxqDzbm"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "control/address";
    var setFlag = [[${@permission.hasPermi('control:address:set')}]];
    var checkFlag = [[${@permission.hasPermi('control:address:check')}]];
    var mobile = $.common.isMobile();

    $(function () {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "走访地址簿",
            sortName: "cjsj",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'dzbm',
                    title: '地址编码',
                    visible: false
                },
                {
                    field: 'dzlx',
                    title: '地址类型',
                    formatter: function (value, row, index) {
                        if (value === 'FW') {
                            return "房屋";
                        } else if (value === 'JZW') {
                            return "建筑物";
                        }
                    }
                },
                {
                    field: 'dzmc',
                    title: '地址名称'
                },
                {
                    field: 'havefw',
                    title: '是否有房屋',
                    formatter: function (value, row, index) {
                        if (value === 'Y') {
                            return "有";
                        } else if (value === 'N') {
                            return "无";
                        }
                    }
                },
                {
                    field: 'zdlx',
                    title: '重点地址类型'
                },
                {
                    field: 'ssjlxxqDzbm_dictText',
                    title: '街路巷名称'
                },
                {
                    field: 'ssjwq_dictText',
                    title: '所属警务区'
                },
                {
                    field: 'policeName',
                    title: '责任民警'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (mobile) {
                            if (row.resultId === null && row.templateId !== null) {
                                actions.push('<a class="btn btn-primary btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="checkInfo(\'' + row.templateId + '~' + row.dzbm + '\')"><i class="fa fa-eye"></i> 监督检查</a> ');
                            }
                        } else {
                            if (row.templateId === null) {
                                actions.push('<a class="btn btn-info btn-xs ' + setFlag + '" href="javascript:void(0)" onclick="setTemplate(\'' + row.dzbm + '\')"><i class="fa fa-tags"></i> 设置模板</a> ');
                            } else {
                                if(row.resultId !== null){
                                // if (row.addressId !== null) {
                                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="seeResult(\'' + row.dzbm  + '\')"><i class="fa fa-search"></i> 检查结果</a> ');
                                }
                                // }else{
                                actions.push('<a class="btn btn-primary btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="checkInfo(\'' + row.templateId + '~' + row.dzbm + '\')"><i class="fa fa-eye"></i> 监督检查</a> ');
                                // }
                                actions.push('<a class="btn btn-success btn-xs ' + setFlag + '" href="javascript:void(0)" onclick="updateTemplate(\'' + row.dzbm + '\')"><i class="fa fa-tags"></i> 更新模板</a> ');
                            }
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="sendAnnounce(\'' + row.dzbm + '\')"><i class="fa fa-send"></i> 隐患通知</a> ');
                            actions.push('<a class="btn btn-police btn-xs" href="javascript:void(0)" onclick="setPolice(\'' + row.dzbm + '\')"><i class="fa fa-street-view"></i> 责任人</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function setTemplate(dzbm) {
        var url = $.common.setURL(prefix + "/setTemplate/" + dzbm);
        var title = "模板设置";
        open(title, url);
    }

    function updateTemplate(dzbm) {
        $.modal.confirm("该信息已存在检查模板，确认要替换吗?", function () {
            var url = $.common.setURL(prefix + "/setTemplate/" + dzbm);
            var title = "模板设置";
            open(title, url);
        });
    }

    function open(title, url) {
        layer.open({
            type: 2,
            area: ['800px', '500px'],
            title: title,
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function (index) {
                return true;
            }
        });
    }

    function checkInfo(check) {
        // $.get($.common.setURL("/control/result/isResult/" + check.split("~")[1]), function (res) {
            // if (res === 0) {
            var url = prefix + '/check/' + check;
            $.modal.openTab("监督检查", $.common.setURL(url));
            // }else{
            //     layer.msg("该地区已经检查完毕，请勿重复操作！", {icon: 0})
            // }
        // })

    }

    function sendAnnounce(dzbm) {
        var _height = ($(window).height() - 50);
        layer.open({
            type: 2,
            area: ['800px', _height + 'px'],
            title: "隐患通知下发",
            content: $.common.setURL("/system/message/announce/" + dzbm),
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function (index) {
                return true;
            }
        });
    }

    function seeResult(id) {
        $.modal.openTab("检查结果", $.common.setURL("/control/result?addressId=" + id));
    }

    function setPolice(id) {
        var url = $.common.setURL(prefix + "/setPolice/" + id);
        open("责任民警", url);
    }
</script>
</body>
</html>
